cmake_minimum_required(VERSION 3.25)

get_filename_component(ProjectId ${CMAKE_CURRENT_SOURCE_DIR} NAME)
string(REPLACE " " "_" ProjectId ${ProjectId})
project(${ProjectId} C)

set(CMAKE_C_STANDARD 11)

# 获取当前目录下所有的子目录
file(GLOB SUBDIRS LIST_DIRECTORIES true ${CMAKE_CURRENT_SOURCE_DIR}/*)

# 循环遍历子目录并添加
foreach(SUBDIR ${SUBDIRS})
	if(IS_DIRECTORY ${SUBDIR})
		get_filename_component(DIR_NAME ${SUBDIR} NAME)

		# 排除特定的目录
		if(DIR_NAME STREQUAL ".idea" OR DIR_NAME STREQUAL "cmake-build-debug")
			continue()
		endif()

		# 检查是否包含 CMakeLists.txt 文件
		file(GLOB CMAKE_FILES ${SUBDIR}/CMakeLists.txt)
		if(CMAKE_FILES)
			add_subdirectory(${DIR_NAME})
		endif()
	endif()
endforeach()
